//封装了request请求
import QS from "qs"; // 引入qs模块，用来序列化post类型的数据
// const BASE_URL =  "http://localhost:8000" //链接前缀
 //"http://127.0.0.1:4523/mock/418628" //mook接口
 //const BASE_URL = "http://127.0.0.1:4523/mock/418628"
// const BASE_URL = "http://47.113.203.45:81"
const BASE_URL = "http://localhost:81"
 //const BASE_URL = "http://127.0.0.1:4523/mock/418628"
//判卷网址
const JUDGE_URL = "http://localhost:10010"

//定义异常返回信息
const error = {
  code: 500,
  msg: "请求异常",
  data: null
};

export const myRequest = (url,data,method)=>{
	return new Promise((resolve,reject)=>{
		uni.request({
			url : BASE_URL + url,
			method:method || 'GET',
			data:data || {},
			success: (res) => {
				 // if(res.data.code !== 200){
				 // 	return uni.showToast({
				 // 		title:"获取数据失败"
				 // 	})
				 // }
				resolve(res)
			},
			fail: (err) => {
				uni.showToast({
					title:"请求接口失败"
				})
				reject(err)
			}
		})
	})
};

//判卷接口
export const JudgeRequest = (url,data,method)=>{
	return new Promise((resolve,reject)=>{
		uni.request({
			url : JUDGE_URL + url,
			method:method || 'GET',
			data:data || {},
			success: (res) => {
				 // if(res.data.code !== 200){
				 // 	return uni.showToast({
				 // 		title:"获取数据失败"
				 // 	})
				 // }
				resolve(res)
			},
			fail: (err) => {
				uni.showToast({
					title:"请求接口失败"
				})
				reject(err)
			}
		})
	})
}
